try!(rm_rf(&layout.fingerprint(&pkg)));
let profiles = [Profile::default_dev(), Profile::default_test()];
for profile in profiles.iter() {
- for filename in try!(cx.target_filenames(target, profile)).iter() {
+ for filename in try!(cx.target_filenames(&pkg, target, profile)).iter() {
try!(rm_rf(&layout.dest().join(&filename)));
try!(rm_rf(&layout.deps().join(&filename)));
}
}
/// Get the metadata for a target in a specific profile
- pub fn target_metadata(&self, target: &Target, profile: &Profile)
- -> Option<Metadata> {
+ pub fn target_metadata(&self, pkg: &Package, target: &Target,
+ profile: &Profile) -> Option<Metadata> {
let metadata = target.metadata();
if target.is_lib() && profile.test {
// Libs and their tests are built in parallel, so we need to make
})
} else if target.is_bin() && profile.test {
// Make sure that the name of this test executable doesn't
- // conflicts with a library that has the same name and is
+ // conflict with a library that has the same name and is
// being tested
- let mut metadata = self.resolve.root().generate_metadata();
+ let mut metadata = pkg.package_id().generate_metadata();
metadata.mix(&format!("bin-{}", target.name()));
Some(metadata)
+ } else if pkg.package_id() == self.resolve.root() && !profile.test {
+ // If we're not building a unit test then the root package never
+ // needs any metadata as it's guaranteed to not conflict with any
+ // other output filenames. This means that we'll have predictable
+ // file names like `target/debug/libfoo.{a,so,rlib}` and such.
+ None
} else {
metadata.map(|m| m.clone())
}
}
/// Returns the file stem for a given target/profile combo
- pub fn file_stem(&self, target: &Target, profile: &Profile) -> String {
- match self.target_metadata(target, profile) {
+ pub fn file_stem(&self, pkg: &Package, target: &Target,
+ profile: &Profile) -> String {
+ match self.target_metadata(pkg, target, profile) {
Some(ref metadata) => format!("{}{}", target.crate_name(),
metadata.extra_filename),
None if target.allows_underscores() => target.name().to_string(),
/// Return the filenames that the given target for the given profile will
/// generate.
- pub fn target_filenames(&self, target: &Target, profile: &Profile)
- -> CargoResult<Vec<String>> {
- let stem = self.file_stem(target, profile);
+ pub fn target_filenames(&self, pkg: &Package, target: &Target,
+ profile: &Profile) -> CargoResult<Vec<String>> {
+ let stem = self.file_stem(pkg, target, profile);
let suffix = if target.for_host() {&self.host_exe} else {&self.target_exe};
let mut ret = Vec::new();
let root = cx.out_dir(pkg, kind, target);
let mut missing_outputs = false;
if !profile.doc {
- for filename in try!(cx.target_filenames(target, profile)).iter() {
+ for filename in try!(cx.target_filenames(pkg, target, profile)).iter() {
missing_outputs |= fs::metadata(root.join(filename)).is_err();
}
}
cx.compilation.extra_env.insert("OUT_DIR".to_string(), out_dir);
for &(target, profile) in targets {
- for filename in try!(cx.target_filenames(target, profile)).iter() {
+ for filename in try!(cx.target_filenames(pkg, target, profile)).iter() {
let dst = cx.out_dir(pkg, Kind::Target, target).join(filename);
if profile.test {
cx.compilation.tests.push((target.name().to_string(), dst));
if profile.doc { continue }
if cx.compilation.libraries.contains_key(&pkgid) { continue }
- let v = try!(cx.target_filenames(target, profile));
+ let v = try!(cx.target_filenames(pkg, target, profile));
let v = v.into_iter().map(|f| {
(target.clone(),
cx.out_dir(pkg, Kind::Target, target).join(f))
}
let exec_engine = cx.exec_engine.clone();
- let filenames = try!(cx.target_filenames(target, profile));
+ let filenames = try!(cx.target_filenames(package, target, profile));
let root = cx.out_dir(package, kind, target);
// Prepare the native lib state (extra -L and -l flags)
let rustc_dep_info_loc = if do_rename {
root.join(&crate_name)
} else {
- root.join(&cx.file_stem(target, profile))
+ root.join(&cx.file_stem(package, target, profile))
}.with_extension("d");
let dep_info_loc = fingerprint::dep_info_loc(cx, package, target,
profile, kind);
None => {}
}
- match cx.target_metadata(target, profile) {
+ match cx.target_metadata(pkg, target, profile) {
Some(m) => {
cmd.arg("-C").arg(&format!("metadata={}", m.metadata));
cmd.arg("-C").arg(&format!("extra-filename={}", m.extra_filename));
Kind::Target => Kind::Target,
});
- for filename in try!(cx.target_filenames(target, profile)).iter() {
+ for filename in try!(cx.target_filenames(pkg, target, profile)).iter() {
if filename.ends_with(".a") { continue }
let mut v = OsString::new();
v.push(&target.crate_name());
format!("\
{compiling} {name} v{version} ({url})
{running} `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
- -C metadata=[..] \
- -C extra-filename=-[..] \
--out-dir {dir}{sep}target{sep}debug \
--emit=dep-info,link \
-L dependency={dir}{sep}target{sep}debug \
execs().with_status(0).with_stdout(&format!("\
{compiling} test v0.0.0 ({url})
{running} `rustc src[..]lib.rs --crate-name test --crate-type lib -g \
- -C metadata=[..] \
- -C extra-filename=-[..] \
--out-dir {dir}[..]target[..]debug \
--emit=dep-info,link \
-L dependency={dir}[..]target[..]debug \
{compiling} test v0.0.0 ({url})
{running} `rustc src[..]lib.rs --crate-name test --crate-type lib \
-C opt-level=3 \
- -C metadata=[..] \
- -C extra-filename=-[..] \
--out-dir {dir}[..]target[..]release \
--emit=dep-info,link \
-L dependency={dir}[..]target[..]release \
{compiling} test v0.0.0 ({url})
{running} `rustc src[..]lib.rs --crate-name test --crate-type lib \
-C opt-level=3 \
- -C metadata=[..] \
- -C extra-filename=-[..] \
--out-dir {dir}[..]target[..]release \
--emit=dep-info,link \
-L dependency={dir}[..]target[..]release \
"));
});
+test!(predictable_filenames {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lib]
+ name = "foo"
+ crate-type = ["staticlib", "dylib", "rlib"]
+ "#)
+ .file("src/lib.rs", "");
+
+ assert_that(p.cargo_process("build").arg("-v"),
+ execs().with_status(0));
+ assert_that(&p.root().join("target/debug/libfoo.a"), existing_file());
+ assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
+ let dylib_name = format!("{}foo{}", env::consts::DLL_PREFIX,
+ env::consts::DLL_SUFFIX);
+ assert_that(&p.root().join("target/debug").join(dylib_name),
+ existing_file());
+});
+
test!(dashes_to_underscores {
let p = project("foo")
.file("Cargo.toml", r#"
--extern a=[..]liba-[..].rlib`
{running} `[..]foo-[..]build-script-build[..]`
{running} `rustc [..]lib.rs --crate-name foo --crate-type lib -g \
- -C metadata=[..] -C extra-filename=-[..] \
--out-dir [..]target[..]debug --emit=dep-info,link \
-L [..]target[..]debug -L [..]target[..]deps`
", compiling = COMPILING, running = RUNNING)));
{running} `rustc src{sep}lib.rs --crate-name test --crate-type lib \
-C opt-level=1 \
-C debug-assertions=on \
- -C metadata=[..] \
- -C extra-filename=-[..] \
-C rpath \
--out-dir {dir}{sep}target{sep}debug \
--emit=dep-info,link \
{running} `rustc src{sep}lib.rs --crate-name test --crate-type lib \
-C opt-level=1 \
-g \
- -C metadata=[..] \
- -C extra-filename=-[..] \
--out-dir {dir}{sep}target{sep}release \
--emit=dep-info,link \
-L dependency={dir}{sep}target{sep}release \